﻿using System;
using System.Windows;
using System.Windows.Media;
using MaxStoreErp.Core.BaseClasses;
using MaxStoreErp.Core.Commands;
using MaxStoreErp.Core.Interfaces;
using MaxStoreErp.Core.Security;
using MaxStoreErp.Core.Ui.MainMenu;
using MaxStoreShop.Dal.Repositories.Shop;
using MaxStoreShop.Logic.RepositoriesContracts.Shop;
using MaxStoreShop.Logic.Services.Shop;
using MaxStoreShop.Logic.ServicesContracts.Shop;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;

namespace MaxStoreShop.ShopModule
{
    [Module(ModuleName = "MaxStoreShop.ShopModule")]
    [ModuleDependency("MaxStoreShop.CoreModule")]
    public class ShopModule : ModuleBase
    {
        protected override string ModuleName
        {
            get { return "Магазин"; }
        }

        protected override void RegisterServices()
        {
            base.RegisterServices();
            UnityContainer.RegisterType<IDebtorRuleRepository, DebtorRuleRepository>()
                .RegisterType<IDebtorRuleService, DebtorRuleService>();
        }

        protected override void RegisterMenuItems()
        {
            base.RegisterMenuItems();
            var icons = new ResourceDictionary
            {
                Source = new Uri("/MaxStoreShop.Media;component/Icons.xaml", UriKind.RelativeOrAbsolute)
            };

            MainMenuService.Add(new MenuItemControl
            {
                TileCaption = "Правила должников",
                GroupName = "Магазин",
                IsTileVisible = PermissionHelper.IsAdmin(),
                IconData = icons["DebtorRuleIcon"] as Geometry,
                Command =
                    new RelayCommand(() => UnityContainer.Resolve<IDocumentManager>().NavigateTo<DebtorRules.DebtorRulesPresenter>())
            });
        }
    }
}
